package com.example.PolimiAssistant.common;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.Wsdl2Code.WebServices.PolimiAssistant.NomClassroom;
import com.example.PolimiAssistant.R;

import java.util.List;

/**
 * Created by Vlado on 09.06.2014.
 */
public class ClassroomAdapter extends ArrayAdapter<NomClassroom> {
    int resource;
    String response;
    Context context;

    public ClassroomAdapter(Context context, int resource, List<NomClassroom> items) {
        super(context, resource, items);
        this.resource=resource;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        LinearLayout classroomView;
        NomClassroom classroom = getItem(position);

        //Inflate the view
        if(convertView==null)
        {
            classroomView = new LinearLayout(getContext());
            String inflater = Context.LAYOUT_INFLATER_SERVICE;
            LayoutInflater vi;
            vi = (LayoutInflater)getContext().getSystemService(inflater);
            vi.inflate(resource, classroomView, true);
        }
        else
        {
            classroomView = (LinearLayout) convertView;
        }
        //Get the text boxes from the classroom_list_item.xml file
        TextView cBuilding =(TextView)classroomView.findViewById(R.id.txtBuilding);
        TextView cFloor =(TextView)classroomView.findViewById(R.id.txtFloor);
        TextView cName =(TextView)classroomView.findViewById(R.id.txtName);

        //Assign the appropriate data from our alert object above
        cBuilding.setText(classroom.building);
        cFloor.setText(String.valueOf(classroom.floor));
        cName.setText(classroom.name);
        return classroomView;
    }
}
